#include <iostream>
#include <cstring>
using namespace std;
const int N = 1010;
int dp[N][N];
int n , m;
int v[N] , w[N];
int main()
{
    cin >> n >> m;
    for(int i = 1;i <= n;i ++) cin >> v[i] >> w[i];
    for(int i = 1;i <= n;i ++)
    {
        for(int j = 0;j <= m;j ++)
        {
            dp[i][j] = dp[i-1][j];
            if(j >= v[i])
            {
                dp[i][j] = max(dp[i][j],dp[i][j-v[i]] + w[i]);
            }
        }
    }
    cout << dp[n][m] << endl;
    memset(dp , -0x3f3f3f3f , sizeof dp);
    dp[0][0] = 0;
    for(int i = 1;i <= n;i ++)
    {
        for(int j = 0;j <= m;j ++)
        {
            dp[i][j] = dp[i-1][j];
            if(j >= v[i])
            {
                dp[i][j] = max(dp[i][j],dp[i][j-v[i]] + w[i]);
            }
        }
    }
    if(dp[n][m] < 0) cout << 0 << endl;
    else cout << dp[n][m] << endl;
    return 0;
}